/* 
 初始化所有图表
 数据抽离在此F
 */
/* 道路预结算 */
var chartData1 = {
    title: '道路预结算',
    xAxis: ['一号路', '二号路', '三号路', '四号路', '五号路', '六号路', '七号路', '八号路', '九号路', '十号路'],
    data: [
        {
            name: '道理养护结算',
            data: [100, 200, 400, 500, 600, 600, 600, 800, 99, 220]
        },
        {
            name: '道路养护预算',
            data: [120, 100, 300, 520, 650, 610, 570, 300, 199, 290]
        }
    ]
};
/* 三甲路  */
var chartData2 = {
    title: '三甲路',
    yAxis: ['预算小结', '结算小结'],
    data: [180, 2200]
};
var chartData11 = {
    title: '道路预结算',
    xAxis: ['一号路', '二号路', '三号路', '四号路', '五号路', '六号路', '七号路', '八号路', '九号路', '十号路'],
    data: [
        {
            name: '道理养护结算',
            data: [120, 200, 400, 500, 60, 600, 600, 800, 199, 220]
        },
        {
            name: '道路养护预算',
            data: [110, 100, 300, 20, 650, 610, 570, 300, 99, 290]
        }
    ]
};
var chartData21 = {
    title: '三甲路',
    yAxis: ['预算小结', '结算小结'],
    data: [1700, 2100]
};
/* 道路等级统计 */
var chartData3 = {
    title: '道路等级统计',
    data: [
        {
            name: 'A级',
            value: 20
        },
        {
            name: 'B级',
            value: 20
        },
        {
            name: 'C级',
            value: 40
        },
        {
            name: 'D级',
            value: 10
        }
    ]
};

/* 养护状况统计 */
var chartData4 = {
    title: '养护状况统计',
    data: [
        {
            name: '不合格',
            value: 5
        },
        {
            name: '合格',
            value: 20
        },
        {
            name: '良好',
            value: 40
        },
        {
            name: '优秀',
            value: 80
        }
    ]
};

/* 养护状况统计 */
var chartData4 = {
    title: '养护状况统计',
    data: [
        {
            name: '不合格',
            value: 5
        },
        {
            name: '合格',
            value: 20
        },
        {
            name: '良好',
            value: 40
        },
        {
            name: '优秀',
            value: 80
        }
    ]
};

/* 保养建议 */
var chartData5 = {
    title: '保养建议',
    data: [
        {
            name: '完好',
            value: 5
        },
        {
            name: '保养小修',
            value: 20
        },
        {
            name: '中修',
            value: 40
        },
        {
            name: '大修',
            value: 80
        },
        {
            name: '更新改造',
            value: 7
        }
    ]
};

/* 应急事件管理 */
var chartData6 = {
    title: '应急事件管理',
    data: [
        {
            name: '处理中',
            value: 25
        },
        {
            name: '已处理',
            value: 80
        }
    ]
};

/* 物资库存管理 */
var chartData7 = {
    title: '物资库存管理',
    xAxis: ['已申请入库', '已审批入库', '待入库', '库存', '申请出库', '已审批出库', '已出库'],
    data: [0]
};

/* 病害分类 */
var chartData8 = {
    title: '病害分类',
    xAxis: ['坑槽', '裂缝', '破碎', '剥离', '松动', '沉陷', '拱起', '拥包', '接缝料损坏', '边角剥落', '污染', '缺钙', '脱落', '井盖高差', '积水', '病害', '桥面拥包'],
    series: [{data:[0, 0, 0]},{data:[0,0,0]},{data:[0,0,0]}]
};

/* 病害处理 */
var chartData9 = {
    title: '病害处理',
    xAxis: ['设施投诉', '已录入', '已暂存', '转维修', '已接受', '已退回', '已修复', '修复确认', '已处理', '无效病害', '已收方', '不合格', '合格'],
    data: [0]
};

/* 病害处理流程 chart1*/
var createChart1 = function (chartData, dom) {
    var option = _.cloneDeep($.lineBarOption);
    var series = [
        {
            type: 'bar',
            barMaxWidth: 16,
            itemStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#f85e14' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#8835e5' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            }
        },
        {
            type: 'line',
            itemStyle: {
                color: '#1dee89'
            }
        }
    ];
    var legend = [];
    for (var i = 0; i < chartData.data.length; i++) {
        series[i].name = chartData.data[i].name;
        series[i].data = chartData.data[i].data;
        legend.push(chartData.data[i].name);
    }
    option.title.text = chartData.title;
    option.series = series;
    option.xAxis[0].data = chartData.xAxis;
    option.legend.data = legend;
    drawCharts(option, dom);
};

/* 三甲路 */
var createChart2 = function (chartData, dom) {
    var option = _.cloneDeep($.horizontalOption);
    var series = [
        {
            itemStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 1,
                    y2: 0,
                    colorStops: [{
                        offset: 0, color: '#edfb4e' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#51f964' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            }
        },
        {
            itemStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 1,
                    y2: 0,
                    colorStops: [{
                        offset: 0, color: '#fea746' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#f63524' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            }
        }
    ];
    for (var i = 0; i < chartData.data.length; i++) {
        series[i].value = chartData.data[i];
        series[i].name = chartData.yAxis[i];
    }
    option.series = [{
        type: 'bar',
        barMaxWidth: 40,
        data: series
    }];
    option.title.text = chartData.title;
    option.yAxis[0].data = chartData.yAxis;
    drawCharts(option, dom);
};

/* 南丁格尔玫瑰图 */
var createPieChart = function (chartData, dom) {
    var option = _.cloneDeep($.pieChart);
    var legend = [];
    for (var i = 0; i < chartData.data.length; i++) {
        legend.push(chartData.data[i].name);
        chartData.data[i].itemStyle = {
            shadowColor: 'rgba(0, 0, 0, 0.5)',
            shadowBlur: 10
        }
    }
    option.legend.data = legend;
    option.legend.orient = 'vertical';
    option.series[0].name = chartData.title;
    option.series[0].data = chartData.data;
    option.title.text = chartData.title;
    drawCharts(option, dom);
};

/* 柱状图 */
var createBarChart = function (chartData, dom, colors, legendData) {
    legendData = legendData || [];
    var option = _.cloneDeep($.lineBarOption);
    var series = [
        {
            name: legendData[0] || '',
            type: 'bar',
            barMaxWidth: 36,
            label: {
                show: true,
                position: 'top',
                color: colors[0],
                fontSize: 14
            },
            itemStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: colors[0] // 0% 处的颜色
                    }, {
                        offset: 1, color: colors[1] // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            },
            data: chartData.data
        }
    ];
    option.title.text = chartData.title;
    option.series = series;
    option.legend.data = legendData;
    option.legend.show = legendData.length ? true : false;
    option.xAxis[0].data = chartData.xAxis;
    option.xAxis[0].axisLabel.rotate = 0;
    drawCharts(option, dom);
};

var createLineChart = function (chartData, dom) {
    var option = _.cloneDeep($.lineBarOption);
    var series = [
        {
            type: 'line',
            barMaxWidth: 36,
            symbolSize: 10,
            itemStyle: {
                color: 'rgba(0, 0, 0, 0)',
                borderColor: '#09ebe9',
                borderWidth: 1
            },
            lineStyle: {
                color: '#09ebe9'
            },
            data: chartData.data
        }
		
    ];
    option.title.text = chartData.title;
    option.series = series;
    option.xAxis[0].data = chartData.xAxis;
    option.xAxis[0].axisLabel.rotate = 0;
    drawCharts(option, dom);
};
var createLineChart8 = function (chartData, dom) {
    var option = _.cloneDeep($.lineBarOption);
    // var color = ['#09ebe9','#ED7C30','#80FF80']
    var series = [
        {
            name:'道路',
            type: 'line',
            barMaxWidth: 36,
            symbolSize: 10,
            itemStyle: {
            color: '#09ebe9',
            borderColor: '#09ebe9',
            borderWidth: 1
            },
            lineStyle: {
                color: '#09ebe9'
            },
            data: chartData.data
        },
        {
            name:'桥梁',
            type: 'line',
            barMaxWidth: 36,
            symbolSize: 10,
            itemStyle: {
                color: '#ED7C30',
                borderColor: '#ED7C30',
                borderWidth: 1,
            },
            lineStyle: {
                color: '#ED7C30'
            },
            data: chartData.bridge
        },
        {
            name:'隧道',
            type: 'line',
            barMaxWidth: 36,
            symbolSize: 10,
            itemStyle: {
                color: '#80FF80',
                borderColor: '#80FF80',
                borderWidth: 1
            },
            lineStyle: {
                color: '#80FF80'
            },
            data: chartData.tunnel
        },
        
    ];
    var legend = {
        data:['道路','桥梁','隧道'],
        right:'left',
        top:'0',
        itemWidth:10,//图例的宽度
        itemHeight:10,//图例的高度
        textStyle:{//图例文字的样式
        color:['#09ebe9','#ED7C30','#80FF80'],
        fontSize:18
        }
    }
    option.title.text = chartData.title;
    option.series = series;
    option.xAxis[0].data = chartData.xAxis;
    option.xAxis[0].axisLabel.rotate = 0;
    option.legend = legend;
    drawCharts(option, dom);
    // option.color = color
};

var drawCharts = function (option, dom) {
    var chart = echarts.init(dom);
    chart.setOption(option);
};
if(window.BMap){
    window.map = new BMap.Map("mapCont");    // 创建Map实例
}
var createMap = function () {
    // 百度地图API功能
	//获得接口中提供的中心点和地图精度
	$.get(baseUrl+'dlssxx/main/systemparam/getmaplocationinfo',function(data){
		var jsonData=JSON.parse(data);
		map.centerAndZoom(new BMap.Point(jsonData.fDefaultLon,jsonData.fDefaultLat), jsonData.fDefaultPrecision);  // 初始化地图,设置中心点坐标和地图级别
		map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
		map.setMapStyleV2({styleJson: mapStyle});
	});

map.addControl(
      new BMap.MapTypeControl({
        mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP]
      })
    );   
 
};
$(function () {
    /* 道路预结算 chart1*/
    // createChart1(chartData1, $('#chart1')[0]);
    /* 三甲路 chart2*/
    // createChart2(chartData2, $('#chart2')[0]);
    /* 道路等级统计 chart3*/
    // createPieChart(chartData3, $('#chart3')[0]);
    /* 养护状况统计 chart4*/
    // createPieChart(chartData4, $('#chart4')[0]);
    /* 养护状况统计 chart5*/
    // createPieChart(chartData5, $('#chart5')[0]);
    /* 应急事件管理 chart6*/
    // createPieChart(chartData6, $('#chart6')[0]);
    /* 物资库存管理 chart7*/
    // createBarChart(chartData7, $('#chart7')[0], ['#64fa63', '#f3fb4e']);
    /* 病害处理 chart8*/
    // createLineChart(chartData8, $('#chart8')[0]);
    /* 病害处理 chart9*/
    // createBarChart(chartData9, $('#chart9')[0], ['#26ffea', '#b9ff8a'], ['数量'])
});
// var createMap = function () {
//     // 百度地图API功能
//     var map = new BMap.Map("mapCont");    // 创建Map实例
//     map.centerAndZoom(new BMap.Point(108.95746,34.276721), 13);  // 初始化地图,设置中心点坐标和地图级别
//     map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
//     map.setMapStyleV2({styleJson: mapStyle});
// };